﻿//-------------------------------------------------------------------
//	Copyright (c) 2012  Zhirnov Andrey
//	This file is part of the "OGL-Tools" project.
//	See copyright notice in "ShaderSaver.h".
//-------------------------------------------------------------------

#include "../gl_interceptor.h"

#if 0 //def __UX_DEBUG__

using namespace gl;
using namespace UX_STL;

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	HMODULE	h_instance = GetModuleHandle( (LPCSTR)NULL );
	
	WNDCLASSEXA		windowClass = {0};
	windowClass.cbSize			= sizeof(windowClass);
	windowClass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	windowClass.lpfnWndProc		= &DefWindowProcA;
	windowClass.cbClsExtra		= 0;
	windowClass.cbWndExtra		= 0;
	windowClass.hInstance		= h_instance;
	windowClass.hbrBackground	= (HBRUSH)COLOR_WINDOWFRAME;
	windowClass.hIcon			= (HICON) nullptr;
	windowClass.hCursor			= LoadCursor( nullptr, IDC_ARROW );
	windowClass.lpszMenuName	= nullptr;
	windowClass.lpszClassName	= "logger_test";
	windowClass.hIconSm			= (HICON) nullptr;

	CHECK_RETURN( RegisterClassEx( &windowClass ) != 0 );


	HWND	h_wnd = CreateWindowEx(	WS_EX_APPWINDOW,
									"logger_test",
									"GL Logger",
									WS_OVERLAPPEDWINDOW,
									300,	300,
									860,	680,
									NULL,	NULL,
									h_instance,
									NULL );

	SetForegroundWindow( h_wnd );
	ShowWindow( h_wnd, SW_SHOWNA );

	PIXELFORMATDESCRIPTOR pfd = {0};
	
	pfd.nSize		= sizeof( PIXELFORMATDESCRIPTOR );
	pfd.nVersion	= 1;
	pfd.dwFlags		= PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType	= PFD_TYPE_RGBA;
	pfd.cColorBits	= 32;
	pfd.cDepthBits	= 24;
	pfd.cStencilBits= 0;
	pfd.iLayerType	= PFD_MAIN_PLANE;

	HDC		h_dc = GetDC( h_wnd );
	HGLRC	h_rc = nullptr;
	uint	u_pf = ChoosePixelFormat( h_dc, &pfd );

	SetPixelFormat( h_dc, u_pf, &pfd );
	h_rc = wglCreateContext( h_dc );
	wglMakeCurrent( h_dc, h_rc );
	
	GLint	i_major = 0;
	GLint	i_minor = 0;
	glGetIntegerv( GL_MAJOR_VERSION, &i_major );
	glGetIntegerv( GL_MINOR_VERSION, &i_minor );

	PFNwglCreateContextAttribsARBPROC wglCreateContextAttribsARB = (PFNwglCreateContextAttribsARBPROC)wglGetProcAddress( "wglCreateContextAttribsARB" );
	PFNglShaderSourcePROC	glShaderSource = (PFNglShaderSourcePROC) wglGetProcAddress( "glShaderSource" );
	PFNglCreateShaderPROC	glCreateShader = (PFNglCreateShaderPROC) wglGetProcAddress( "glCreateShader" );
	PFNglCompileShaderPROC	glCompileShader = (PFNglCompileShaderPROC) wglGetProcAddress( "glCompileShader" );

	const int	a_attribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
		WGL_CONTEXT_MINOR_VERSION_ARB, 2,
		WGL_CONTEXT_FLAGS_ARB,         WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
		WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
		0, 0
	};

	wglMakeCurrent( h_dc, nullptr );
	wglDeleteContext( h_rc );

	h_rc = wglCreateContextAttribsARB( h_dc, 0, a_attribs );
	
	wglMakeCurrent( h_dc, h_rc );

	GLuint	shader = 0;
	shader = glCreateShader( GL_VERTEX_SHADER );
	
	static const char	*a_source = "void main() {}";

	glShaderSource( shader, 1, &a_source, 0 );
	glCompileShader( shader );

	wglMakeCurrent( h_dc, nullptr );
	wglDeleteContext( h_rc );
	ReleaseDC( h_wnd, h_dc );
	DestroyWindow( h_wnd );

	return 0;
}

#endif	// __UX_DEBUG__